package com.demo.controller;


import java.util.List;

import com.demo.annotation.GlobalInterceptor;
import com.demo.entity.dto.SessionWebUserDto;
import com.demo.entity.po.Violation;

import com.demo.entity.query.ViolationQuery;

import com.demo.entity.vo.PaginationResultVO;

import com.demo.entity.vo.ResponseVO;

 import org.springframework.web.bind.annotation.RequestBody;

import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import com.demo.service.ViolationService;

/**
 * @Description:违规记录表Controller
 * @Date:2025-03-01
 * @author：author
*/
@RestController
@RequestMapping("/violation")
public class ViolationController extends ABaseController {

	@Resource
	private ViolationService violationService;

	/**
	 * 违规记录管理员查询
	 */
	@RequestMapping("/loadDataList4Admin")
	@GlobalInterceptor(checkAdmin = true)
	public ResponseVO loadDataList(ViolationQuery query) {
		query.setOrderBy("create_time desc");
		query.setQueryUserInfo(true); // 查询用户信息
		return getSuccessResponseVO(violationService.findListByPage(query));
	}


	/**
	 * 新增处罚记录
	 */
	@RequestMapping("/add")
	@GlobalInterceptor(checkAdmin = true)
	public ResponseVO add(Violation bean) {
		this.violationService.add(bean);
		return getSuccessResponseVO(null);
	}

	/**
	 * 违规用户自己查询
	 */
	@RequestMapping("/loadDataList4User")
	@GlobalInterceptor
	public ResponseVO loadDataList4User(HttpSession session,
										ViolationQuery query) {
		SessionWebUserDto webUserDto = getUserInfoFromSession(session);
		query.setUserId(webUserDto.getUserId());
		query.setOrderBy("create_time desc");
		return getSuccessResponseVO(violationService.findListByParam(query));
	}
}